package com.xj.qq.adapters;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xj.qq.R;
import com.xj.qq.domain.SQLuser;
import com.xj.qq.domain.SQlite;

public class UsersAdapters extends BaseAdapter {
    private Context context;
    private Cursor c;

    public UsersAdapters(Context context, Cursor c) {
        this.context = context;
        this.c = c;
    }
    @Override
    public int getCount() {
        return c.getCount();
    }
    @Override
    public Object getItem(int position) {
        return null;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }
    //装配视图
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoller v;
        if(convertView == null){
            v = new ViewHoller();
            convertView= LayoutInflater.from(context).inflate(R.layout.item,null);
            v.Id = (TextView)convertView.findViewById(R.id.user_id);
            v.name = (TextView)convertView.findViewById(R.id.user_name);
            v.password = (TextView)convertView.findViewById(R.id.user_password);
            convertView.setTag(v);
        }else{
            v=(ViewHoller)convertView.getTag();
        }
        if(c.getCount() != 0){
            if(c.moveToPosition(position)){
                v.Id.setText(SQLuser.getInstance(context).getId(c));
                v.name.setText(SQLuser.getInstance(context).getName(c));
                v.password.setText(SQLuser.getInstance(context).getPassword(c));;
            }
        }
        return convertView;
    }

    class ViewHoller{
        TextView Id, name, password;
    }
}
